package com.baizhi.mall.controller;


import com.baizhi.mall.entity.mysql.BzAdminRoleDO;
import com.baizhi.mall.service.IBzAdminRoleService;
import com.baizhi.mall.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhw
 * @since 2021-05-17
 */
@RestController
@RequestMapping("/adminRole")
public class BzAdminRoleController {
    @Autowired
    private IBzAdminRoleService ars;
    @GetMapping("adminRoles")
    public ResultEntity<List<BzAdminRoleDO>> selectAll(){
        List<BzAdminRoleDO> list= ars.selectAll();
        return ResultEntity.ok(list);
    }
    @GetMapping("/adminRole/{adminId}")
    public ResultEntity<List<BzAdminRoleDO>> selectById(@PathVariable("adminId")Integer adminId){
        List<BzAdminRoleDO> list=ars.selectByAdminId(adminId);
        return ResultEntity.ok(list);
    }
    @PutMapping("/adminRole/{adminId}")
    public ResultEntity<List<BzAdminRoleDO>> insert(@PathVariable("adminId")Integer adminId,@RequestBody Integer[] roleId){
        ars.deleteByAdminId(adminId);
        for (int i=0;i<=roleId.length - 1;i++){
            ars.insert(new BzAdminRoleDO(0,adminId,roleId[i]));
        }
        return ResultEntity.ok();
    }
}

